.386
STACK   SEGMENT USE16 STACK
             DB   200 DUP(0)
STACK   ENDS

DATA     SEGMENT USE16
            GOOD         DB              10, ? , 10 DUP(0) , 0
            N            EQU              1000
            GA1          DB             'BAG',0DH, 6 DUP(0) ,10 
                         DW               35,56,30,25,0       
            GA2          DB              'BOOK',0DH, 5 DUP(0) ,9  
                         DW                12,30,25,5,0
            GAN          DB                N-2 DUP( 'TEMPVALUE' ,0DH,8 ,15,0,20,0,30,0,2,0,0, 0 )     
DATA     ENDS

CODE     SEGMENT USE16
                                ASSUME CS: CODE, DS: DATA, SS:STACK
START: 
            MOV     AX  ,  DATA
            MOV     DS  ,  AX
            MOV     BP  ,  OFFSET GA1
            MOV     AX  ,  0	;表示开始计时
     	    CALL    TIMER
F0:  
            MOV     SI  , OFFSET  GA1
            MOV     AX  ,   [SI+17]
            MOV     BX  ,   [SI+15]
            CMP     AX  ,  BX
            JNZ     F3
            
            MOV  AX, 1	
        	CALL TIMER	;终止计时并显示计时结果(ms)


            MOV    AH  ,  4CH
            INT      21H 

F3:
            MOV  SI  ,  BP
            ADD   SI  ,  17
            MOV  AX ,  [SI]
            INC    AX
            MOV  [SI] , AX
            JMP   F4

F4:
            MOV     SI  , OFFSET  GA1
            MOV     DI  ,   0
            MOV     DX  ,  0

E1:        
            MOV     AL  ,   [SI+11]
            MOV     AH  ,  [SI+12]
            MOV     CL,7
            SHL       AX,CL
            MOV     BL  ,   [SI+13]
            MOV     BH  ,   [SI+14]
            IDIV    BX
            MOV     DX  ,   AX
            MOV     AL  ,   [SI+17]
            MOV     AH  ,   [SI+18]
            MOV    CL,6
            SHL      AX,6
            MOV     CX,DX 
            MOV     BL  ,   [SI+15]
            MOV     BH  ,  [SI+16]
            IDIV    BX
            MOV     DX  ,   AX
            ADD     CX  ,   DX
            MOV     [SI+19] ,   CL
            MOV     [SI+20] ,   CH
            INC     DI
            CMP    DI  ,   N
            JNZ     T1
            JMP     F0

T1:      
            MOV     SI  , OFFSET  GA1
            MOV     AX  ,   DI
            MOV     DX  ,   0
T2:      
            DEC     AX
            ADD     DX  ,   21
            CMP     AX  ,   0
            JNZ     T2
            ADD     SI  ,   DX
            JMP     E1

TIMER	PROC
	PUSH  DX
	PUSH  CX
	PUSH  BX
	MOV   BX, AX
	MOV   AH, 2CH
	INT   21H	     ;CH=hour(0-23),CL=minute(0-59),DH=second(0-59),DL=centisecond(0-100)
	MOV   AL, DH
	MOV   AH, 0
	IMUL  AX,AX,1000
	MOV   DH, 0
	IMUL  DX,DX,10
	ADD   AX, DX
	CMP   BX, 0
	JNZ   _T1
	MOV   CS:_TS, AX
_T0:	POP   BX
	POP   CX
	POP   DX
	RET
_T1:	SUB   AX, CS:_TS
	JNC   _T2
	ADD   AX, 60000
_T2:	MOV   CX, 0
	MOV   BX, 10
_T3:	MOV   DX, 0
	DIV   BX
	PUSH  DX
	INC   CX
	CMP   AX, 0
	JNZ   _T3
	MOV   BX, 0
_T4:	POP   AX
	ADD   AL, '0'
	MOV   CS:_TMSG[BX], AL
	INC   BX
	LOOP  _T4
	PUSH  DS
	MOV   CS:_TMSG[BX+0], 0AH
	MOV   CS:_TMSG[BX+1], 0DH
	MOV   CS:_TMSG[BX+2], '$'
	LEA   DX, _TS+2
	PUSH  CS
	POP   DS
	MOV   AH, 9
	INT   21H
	POP   DS
	JMP   _T0
_TS	DW    ?
 	DB    'Time elapsed in ms is '
_TMSG	DB    12 DUP(0)
TIMER   ENDP

         
                

CODE    ENDS
             END      START